// 进入报告随即加载这几个tab
$(document).ready(function () {
    var totabs = ["tab_gongshang", "tab_related", "tab_news"];
    for (var ii = 0; ii < totabs.length; ii++) {
        loadtabhtml(totabs[ii], 0);
    }
});

// 标签动态加载
$("#middlenav a").click(function () {
    $("#middlenav a").removeClass("navactive");
    $(this).addClass("navactive");
    var $name = $(this).attr("name");
    $(".navbox").hide();
    $("#loadingimg").hide();
    $("#" + $name).show();
    if ($("#" + $name).html().replace(/^\s\s*/, '').replace(/\s\s*$/, '') == "" && $("#" + $name).data("doing") == 0) {
        loadtabhtml($name, 1);
    }
    else if ($("#" + $name).data("doing") == 1 && $("#loadingimg").css("display") == "none") {
        $("#loadingimg").show();
    }
    autohei();
});

function loadtabhtml(tabid, mm) {
    var thetab = $("#" + tabid);
    if (thetab) {
        thetab.data("doing", 1);
        if (mm) {
            $("#loadingimg").show();
        }
        var nurl = location.href;
        if (nurl.indexOf("?") != -1) {
            nurl = nurl + "&part=" + tabid;
        }
        else {
            nurl = nurl + "?part=" + tabid;
        }
        $.ajax({
            url: nurl,
            type: "get",
            success: function (t) {
                $("#" + tabid).html(t);
                $("#" + tabid).data("doing", 0);
                $("#loadingimg").hide();
                autohei();
            }
        });
    }
}

//打印
$("#printbtn").click(function () {
    $("#loadingimg").show();
    $("#middlenav a").each(function () {
        var $name = $(this).attr("name");
        $(".navbox").show();
        $(".hidedetail").show();
        if ($("#" + $name).html().replace(/^\s\s*/, '').replace(/\s\s*$/, '') == "" && $("#" + $name).data("doing") == 0) {
            loadtabhtml($name, 0);
        }
    });
    $("#loadingimg").hide();
    window.print();
});

//PDF
//$("#printpdf").click(function () {
//    window.open(location.href.replace("/report/", "/reportpdf/"));
//});

//table tr的隐藏 和 点击查看更多的事件
function hidetrbox() {
    $(".hidetrbox").each(function () {
        var hidetr = $(this).find(".hidetr");
        var len = hidetr.length;
        var btn = $(this).find(".hidetr_btn");
        if (len > 3) {
            btn.show();
            for (var i = 0; i < len; i++) {
                if (i > 2) {
                    $(hidetr[i]).hide();
                }
            }
        }
    });
    $(".hidetr_btn").unbind('click').click(function () {
        var $this = $(this);
        var val = $this.attr("val");
        var parent = $this.parents(".hidetrbox");
        var hidetr = parent.find(".hidetr");
        if (val == "0") {
            $this.attr("val", "1");
            $this.text("∧ 部分隐藏");
            hidetr.show();
        } else {
            $this.attr("val", "0");
            $this.text("∨ 显示全部");
            for (var i = 0, len = hidetr.length; i < len; i++) {
                if (i > 2) {
                    $(hidetr[i]).hide();
                }
            }
        }
        autohei();
    });
}

//长文本字段的显示与隐藏
var showdetail = function (e) {
    var etcontent = $(e).parents("tr").next().find(".tablecontent");
    var estate = etcontent.css("display");
    var parent = $(e).parent('table');
    parent.find(".hidedetail").hide();
    parent.find(".showdetail-btn").text("查看详情");
    if (estate == "none") {
        etcontent.show();
        $(e).text("收起详情");
    }
    else {
        etcontent.hide();
        $(e).text("查看详情");
    }
    autohei();
};

//tab 显示隐藏 操作后 iframe高度改变
function autohei() {
    if (window.Owner) {
        var tabs = window.Owner.mini.get("mainTabs");
        var title = $("#report-box .companytitle").text();
        var name = "报告: " + title;
        var tab = tabs.getTab(name);
        var iframe = tabs.getTabIFrameEl(tab);
        var hei = iframe.contentWindow.document.getElementById("report-box").scrollHeight + 150;
        if (hei < 700) {
            hei = 700;
        }
        iframe.style.height = hei + 'px';
    }
}

// 报告内部链接，控制tab的切换
function hrefortab() {
    if (window.Owner) {
        $('.otherentatag').unbind('click').click(function () {
            window.Owner.newtab("报告: " + $(this).text(), $(this).attr("href") + "?version=12", 'icon-report12');
            return false;
        });
    }
}

//筛选
function sxdetail(select, othis, boxid) {
    var category = select;
    $(othis).siblings().removeClass("sx-active");
    $(othis).addClass("sx-active");
    if (select == 0 || boxid) {
        $(".sx-detail").hide().find(".sx-active").removeClass("sx-active");
    }
    if (select != 0 && boxid) {
        $("#" + boxid).show();
    }
}
function sxyear(select, othis) {
    var year = select;
    $(othis).siblings().removeClass("sx-active");
    $(othis).addClass("sx-active");
}
